package com.projekt.alpar;

import HatterOsztalyok.Database;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class AllSongsActivity extends ListActivity {
	private Intent intent;

	/**
	 * Létrehozza az activity-t, és feltölti az adatokkal
	 */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.i("AllSongsActivity", "setcontentview elott");
		setContentView(R.layout.allsong);
		Log.i("AllSongsActivity", "setcontentview utan");

		Database adat = new Database(getApplicationContext(),
				getContentResolver(), 1);
		SQLiteDatabase db = adat.getReadableDatabase();

		String oszlopok[] = { "title, artist, rowid as _id" };
		Cursor lekerd = db.query("Music", oszlopok, null, null, null, null,
				null);
		if (lekerd == null)
			Log.e("MyExpandableListAdapter", "Grouplekerdezes==null");
		else if (!lekerd.moveToFirst())
			Log.e("MyExpandableListAdapter", "Group: no query result");
		else {
			startManagingCursor(lekerd);
			Log.i("AllSongsActivity", "startmanaging utan");

			String[] from = { "title", "artist" };
			int[] to = { R.id.text1, R.id.text2 };
			SimpleCursorAdapter songs = new SimpleCursorAdapter(this,
					R.layout.songs_row, lekerd, from, to);
			Log.i("AllSongsActivity", "adapter utan");
			setListAdapter(songs);
			Log.i("AllSongsActivity", "setlist utan");
		}
		adat.close();
		intent = new Intent("com.projekt.alpar.commandevent");
		Log.i("AllSongsActivity", "oncreate vege");
	}

	/**
	 * Ha a felhasználó kiválaszt egy elemet, jelzi a PlayerService-nek, hogy
	 * ezt a zenét játssza le
	 */
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Log.i("AlbumsActivity", "onchildclick meghivva");
		intent.putExtra("source", 3);
		intent.putExtra("count", position);
		intent.putExtra("filter", "");
		sendBroadcast(intent);
	}
}
